# -*- coding: utf-8 -*-
from Crypto.Cipher import DES
import os, sys

#obj=DES.new(key='password', mode=DES.MODE_ECB)
#obj1=DES.new(key='password', mode=DES.MODE_CBC, IV='\0\0\0\0\0\0\0\0')

def encryptFile(input, output=None):
    obj = DES.new(key='wez5deB-', mode=DES.MODE_ECB)
    f = open(input, 'rb'); data = f.read(); f.close()
    #pad data
    pad_len = 8 - (len(data)%8)
    data += pad_len * chr(pad_len)
    e = obj.encrypt(data)
    w = open(output, 'wb'); w.write(e); w.close()

def decryptFile(input, output=None):
    obj=DES.new(key='wez5deB-', mode=DES.MODE_ECB)
    f = open(input, 'rb')
    data = f.read()
    f.close()
    d = obj.decrypt(data)
    #unpad data
    pad_len = ord(d[-1])
    d = d[:-pad_len]
    w = open(output, 'wb')
    w.write(d)
    w.close()

if __name__ == "__main__":
    decryptFile('d:\\temp\\1.ssrt','d:\\t.srt')
#    if len(sys.argv) != 4:
#        print sys.argv[0] + " en/de input output"
#    elif sys.argv[1] == "en":
#        encryptFile(sys.argv[2], sys.argv[3])
#    elif sys.argv[1] == "de":
#        decryptFile(sys.argv[2], sys.argv[3])
#    else:
#        print sys.argv[0] + " en/de input output"

    
